package com.gy.smart.handle;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.gy.smart.R;
import com.gy.smart.base.BaseFragment;
import com.gy.smart.util.FragmentAdapter;
import com.gy.smart.view.TitleView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 高岳 on 2016/12/25.
 * Describe:办事首页
 */
public class HandleFragment extends BaseFragment implements TitleView.TitleSelectListener {

    private TextView tvSearch;
    private TitleView youPinTitleView;
    private ViewPager viewPager;
    private FragmentAdapter fragmentAdapter;
    private List<Fragment> fragments;
    private List<String> titleList;

    @Override
    protected View setView(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.fragment_handle,null);
        setTitleMsg("办事指南");
        _baseBack.setVisibility(View.INVISIBLE);
        return view;
    }

    @Override
    protected void initView() {
        tvSearch = (TextView) _rootView.findViewById(R.id.fg_handle_home_tv_search);
        youPinTitleView = (TitleView) _rootView.findViewById(R.id.fg_handle_home_titleview);
        viewPager = (ViewPager) _rootView.findViewById(R.id.fg_handle_home_viewpage);
    }

    @Override
    protected void initData() {
        fragments = new ArrayList<>();
        fragments.add(new HandleServiceFragment());
        fragments.add(new HandleThemeFragment());
        fragmentAdapter = new FragmentAdapter(getActivity().getSupportFragmentManager(),fragments);
        titleList = new ArrayList<>();
        titleList.add("部门服务");
        titleList.add("办事主题");
    }

    @Override
    protected void setListener() {
        super.setListener();
        tvSearch.setOnClickListener(this);
        youPinTitleView.setMyListener(this);
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }
            @Override
            public void onPageSelected(int position) {
                youPinTitleView.setSelect(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected void fillData() {
        super.fillData();
        youPinTitleView.setmDatas(titleList);
        viewPager.setAdapter(fragmentAdapter);
    }

    @Override
    public void doClick(View v) {
        super.doClick(v);
        switch (v.getId()){
            case R.id.fg_handle_home_tv_search:

                break;
        }
    }

    @Override
    public void titleSelect(int item) {
        viewPager.setCurrentItem(item);
    }
}
